home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: initializeTcb.c,v $
- * $Revision: 1.2 $
- * $Date: 1996/05/04 23:51:54 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "thread_funcs.h"
- #include "queue_globals.h"
- #include "threadstate.h"
- #include "thread_globals.h"
- #include "queue_consist.h"
- #include "ips_support.h"
-
- #ifdef DEBUG
- void
- dumpTcb(
- register TCB *tcb
- )
- {
- static char *states[]={
- "INACTIVE", /* -2 */
- "LOOP",
- "ACTIVE", /* 0 */
- "SEMAPHORE_WAIT",
- "SH_LATCH_WAIT",
- "EX_LATCH_WAIT",
- "SPARE_TCB",
- "DISK_WAIT",
- "RECEIVE_WAIT",
- "DISKOPEN_WAIT",
- "DISKCLOSE_WAIT", /* 8 */
- "LOCK_WAIT",
- "LOCKUPGRADE_WAIT",
- "LOG_QUIESCE_WAIT", /* 11 */
- "TRANS_QUIESCE_WAIT",
- "LOG_RECOVERY_WAIT",
- "BUFGROUP_WAIT",
- "CHECKPOINT_WAIT", /* 15 */
- "DISKFORMAT_WAIT",
- "LOG_CLOSE_WAIT",
- "DISK_Q_WAIT",/* 18 */
- "TRANS_SHUTDOWN_WAIT",
- "LOG_PREFLUSH_WAIT", /* 20 */
- "THREAD_READY_WAIT", /* 21 */
- "THREAD_RECOVER_UNDO_WAIT",
- "THREAD_WAKEUP_WAIT",
- "THREAD_TIMER_IN_USE", /* 24 */
- "DIRTY_PAGE_FLUSH_WAIT", /* 25 */
- "THREAD_FORK_WAIT", /* 26 */
- "THREAD_COORD_WAIT" /* 27 */
- };
-
- fprintf(stderr, "THREAD %d state %d/%s\n",
- tcb->id, tcb->state,
- (tcb->state > MAX_THREADSTATE)?"UNKNOWN STATE": states[tcb->state+2]);
- fprintf(stderr,
- "\t[stk 0x%x, sp 0x%x, size %d\n",
- tcb->stack, tcb->sp, (int)(tcb->sp - tcb->stack));
- fprintf(stderr,
- "\tlists: ctl 0x%x, trans 0x%x\n", tcb->controlList, tcb->transList);
- fprintf(stderr,
- "\tdiskMsg 0x%x, iovec=[0x%x,%d]\n", tcb->diskMessage,
- tcb->iovec[0].iov_base, tcb->iovec[0].iov_len);
- fprintf(stderr,
- "\tinitBuf [sp 0x%x, pc 0x%x] \tcurrentBuf [sp 0x%x, pc 0x%x]\n",
- #ifdef mips
- tcb->initBuf[JB_SP], tcb->initBuf[JB_PC],
- tcb->currentBuf[JB_SP], tcb->currentBuf[JB_PC]
- #elif defined(sparc)
- tcb->initBuf[JB_SP_SPARC], tcb->initBuf[JB_PC_SPARC],
- tcb->currentBuf[JB_SP_SPARC], tcb->currentBuf[JB_PC_SPARC]
- #elif defined(linux)
- LINUX_JB_SP(tcb->initBuf), LINUX_JB_PC(tcb->initBuf),
- LINUX_JB_SP(tcb->currentBuf), LINUX_JB_PC(tcb->currentBuf)
- #elif defined(_IBMR2)
- tcb->initBuf[JB_SP_AIX], tcb->initBuf[JB_PC_AIX],
- tcb->currentBuf[JB_SP_AIX], tcb->currentBuf[JB_PC_AIX]
- #elif defined(hpux)
- HPPA_JB_SP(tcb->initBuf), HPPA_JB_PC(tcb->initBuf),
- HPPA_JB_SP(tcb->currentBuf), HPPA_JB_PC(tcb->currentBuf)
- #elif !(defined(mips) || defined(sparc) || defined(_IBMR2) || defined(hpux) || defined(linux))
- not supported
- #else
- /* this else should have the not supported code, but the
- ultrix cpp is broken */
- #endif
- );
-
- } /* dumpTcb */
-
- void
- dumpActive()
- {
- extern TCB *Active;
- dumpTcb(Active);
- } /* dumpActive */
-
- void
- dumpTcbs()
- {
- register int i;
-
- for (i = 0; i < NumThreads; i++) {
- dumpTcb(&Tcbs[i]);
- }
- dumpActive();
- }
- #endif DEBUG
-
- void
- reinitTcb(TCB *tcb)
- {
- tcb->state = THREAD_INACTIVE;
-
- tcb->transRec = NULL;
- tcb->semCount = 0; /* no semaphores held */
- tcb->replyAddr.sin_family = AF_INET;
- tcb->replyAddr.sin_addr.s_addr = INADDR_ANY;
- tcb->error = tcb->errno = esmNOERROR;
- }
-
- void
- initializeTcb (
-
- register PFI pc,
- register TCB *tcb,
- register FOUR *stack,
- register FOUR stackSize /* not used */
-
- )
- {
-
- #ifdef _IBMR2
- FCN_DESC *fcn_desc;
- #endif
-
- register TCB *locTcb;
-
-
- TRACE(TR_THREAD, TR_LEVEL_1);
-
- /*
- * stack grows down so move the pointer there
- */
- /*stack = &stack[stackSize - 1];*/
-
- /*
- * align the stack pointer
- */
- stack = (long *) (((long) stack) & ~0x7);
- TRPRINT(TR_THREAD, TR_LEVEL_2, ("stack:%x", stack));
- locTcb = tcb;
-
- /*
- * setup the tcb
- */
- #ifdef hpux
- tcb->sp = (long *) &stack[+6];
- stack[5] = FRAMEMARK;
- stack[4] = FRAMEMARK;
- stack[3] = FRAMEMARK;
- stack[2] = FRAMEMARK;
- stack[1] = FRAMEMARK;
- stack[0] = FRAMEMARK;
- #elif defined(sparc) || defined(mips) || defined(_AIX) || defined(linux)
- tcb->sp = (long *) &stack[-6];
- stack[-5] = FRAMEMARK;
- stack[-4] = FRAMEMARK;
- stack[-3] = FRAMEMARK;
- stack[-2] = FRAMEMARK;
- stack[-1] = FRAMEMARK;
- stack[ 0] = FRAMEMARK;
- #else
- not supported
- #endif
- tcb->stack = stack;
- initializeListElement( &(tcb->controlList), (char *) tcb );
- initializeListElement( &(tcb->transList), (char *) tcb );
-
- tcb->diskMessage = (DISKMSG *) &DiskMessages[tcb->id];
- tcb->diskMessage->body.threadId = tcb->id;
- tcb->iovec[0].iov_base = (char *) &(tcb->message);
- tcb->iovec[0].iov_len = sizeof(MESSAGE);
- INIT_TCB_MAGIC(tcb);
- #ifdef IPS_SUPPORT
- tcb->ipsid = IPSnewThread(NULL);
- #endif IPS_SUPPORT
-
-
- /*
- * save this place
- */
- setjmp(tcb->initBuf);
- setjmp(tcb->currentBuf);
-
- reinitTcb(tcb);
-
-
- #ifdef mips
- tcb->initBuf[JB_SP] = (int) tcb->sp;
- tcb->initBuf[JB_PC] = (int) pc;
- tcb->currentBuf[JB_SP] = (int) tcb->sp;
- tcb->currentBuf[JB_PC] = (int) pc;
- #elif defined(linux)
- LINUX_JB_PC(tcb->initBuf) = (int) pc;
- LINUX_JB_SP(tcb->initBuf) = (int) tcb->sp;
- LINUX_JB_PC(tcb->currentBuf) = (int) pc;
- LINUX_JB_SP(tcb->currentBuf) = (int) tcb->sp;
- #elif defined(sparc)
- tcb->initBuf[JB_SP_SPARC] = (int) tcb->sp;
- tcb->initBuf[JB_PC_SPARC] = (int) pc;
- /*
- * NPC is set to 4 from the pc
- */
- tcb->initBuf[JB_NPC_SPARC] = ((int) pc) + sizeof(int);
- tcb->currentBuf[JB_SP_SPARC] = (int) tcb->sp;
- tcb->currentBuf[JB_PC_SPARC] = (int) pc;
- tcb->currentBuf[JB_NPC_SPARC] = ((int) pc) + sizeof(int);
- #elif defined(_IBMR2)
- fcn_desc = (FCN_DESC *) pc;
- tcb->initBuf[JB_SP_AIX] = (int) tcb->sp;
- tcb->initBuf[JB_PC_AIX] = (int) fcn_desc->address;
- tcb->currentBuf[JB_SP_AIX] = (int) tcb->sp;
- tcb->currentBuf[JB_PC_AIX] = (int) fcn_desc->address;
- #elif defined(hpux)
- HPPA_JB_PC(tcb->initBuf) = (int) pc;
- HPPA_JB_SP(tcb->initBuf) = (int) tcb->sp;
- HPPA_JB_PC(tcb->currentBuf) = (int) pc;
- HPPA_JB_SP(tcb->currentBuf) = (int) tcb->sp;
- #elif !(defined(mips) || defined(sparc) || defined(_IBMR2) || defined(hpux) || defined(linux))
- not supported
- #else
- /* this else should have the not supported code, but the
- ultrix cpp is broken */
- #endif
- }
-